import java.util.regex.*;

public class InputParser {
	protected StringBuffer b;
	protected String x;
	protected int y;
	CommandTypes cmd;

	public CommandTypes parse(String s) {
		StringBuffer b;
		CommandTypes cmd;
		cmd = CommandTypes.SETUP;
		b = new StringBuffer(s.toUpperCase());
		int cmdlen = s.length() > 1 ? 2 : 1;
		String command = b.substring(0, cmdlen);
		if (command.equals("EX"))
			cmd = CommandTypes.EXCHANGE;
		else if (command.equals("CH"))
			cmd = CommandTypes.CHELLANGE;
		else if (command.equals("Q"))
			cmd = CommandTypes.QUIT;
		else if (command.equals("SB"))
			cmd = CommandTypes.SCOREBOARD;
		else if (command.equals("?"))
			cmd = CommandTypes.HELP;
		else if (command.equals("P"))
			cmd = CommandTypes.PASS;

		// return cmd;

		switch (cmd) {
		case SETUP:
			
			
			Pattern p = Pattern.compile("^[a-o][1-9][0-5]?\\s[dr]\\s.*",
					Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
			Matcher m = p.matcher(s);

			if (!m.matches()) {
				cmd = CommandTypes.INVALID;

			}

			break;

		}
		return cmd;

	}
}
